#include<stdio.h>
#include<string.h>
#define INF 2000000000
#define M 2100000
#define N 500100
#define min(x,y) ((x)<(y)?(x):(y))
int S, T;
typedef struct {int v, n, q; } ADJ;
ADJ adj[M];
int num = 1;
int node[N];
int h[N], c[N];
int o[N];
int n, m;
int lim;
void addadj(int u, int v, int q)
{
	adj[num].v = v;
	adj[num].q = q;
	adj[num].n = node[u];
	node[u] = num ++;
}
void add(int u, int v, int q)
{
	addadj(u, v, q);
	addadj(v, u, 0);
}
int dfs(int u, int l)
{
	int s = l, i, t, d = lim;
	if(u == T || l == 0) return l;
	for(i=o[u]; i; i=adj[i].n)
	{
		if(adj[i].q > 0)
		{
			if(h[u] == h[adj[i].v]+1)
			{
				t = min(adj[i].q, s);
				t = dfs(adj[i].v, t);
				adj[i].q -= t;
				if(i&1) adj[i+1].q += t; else adj[i-1].q += t;
				s -= t;
				if(h[S]>=lim) return l-s;
				if(s == 0) break;
			}
			if(adj[i].q > 0) d = min(d, h[adj[i].v]); //here
		}
	}
	if(i) o[u] = i; else
	{
		for(i=node[u]; i!=o[u]; i=adj[i].n)
			if(adj[i].q > 0) d = min(d, h[adj[i].v]);
		c[h[u]] --;
		if(c[h[u]] == 0) h[S] = lim;
		h[u] = d+1;
		c[h[u]] ++;
		o[u] = node[u];
	}
	return l-s;
}
int ans = 0;

int main(void)
{
	int i;
	int a, b, x;
	scanf("%d %d", &n, &m);
	for(i=0; i<m; i++)
	{
		scanf("%d %d %d", &a, &b, &x);
		add(a, b, x);
	}
	scanf("%d %d", &S, &T);
	lim = n + 2;
	c[0] = lim;
	memcpy(o, node, sizeof(node));
	while(h[S]<lim) ans += dfs(S, INF);
	printf("%d\n", ans);

	//while(1);
	return 0;
}

